<?php
namespace app\common\controller;

use think\exception\HttpResponseException;
use think\Response;

class Api extends Base {
    protected $userId = 0;
    protected function initialize()
    {
        error_reporting(E_ERROR | E_WARNING | E_PARSE);
        parent::initialize();
        //配置统一入口，只让访问init方法
        if (request()->module() != 'api' || request()->controller() != 'Index' || request()->action() != 'index') {
            die('error');
        }
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods: POST'); // 允许option，get，post请求
    }

    //此方法用于设置参数
    public function setInit($user_id)
    {
        $this->userId = $user_id;
        return true;
    }
}